var Projects = {
	
		projectDialog : function ( ) {
			var dlg = new dijit.Dialog( {
					id 		: "projectDialog",
					title 	: "Manage project",
					href   	: "/FinalProject/templates/projects/newProject.jsp"
			});
			dlg.onCancel = function( ) {
				dijit.byId( "projectDialog").destroyRecursive( );
			}
			dlg.refresh( );
			dlg.show( );
		},
		
		deleteProject : function ( ) {
			if ( dijit.byId( "projectsGrid").selection.getSelected( ).length == 0) {
		        dijit.byId('toaster').setContent('Select project from the grid.', 'fatal');
		        dijit.byId('toaster').show();							
				return;
			}
			dojo.xhrPost( {
				url 		: "/FinalProject/app/projectManagement",
				content		: { projectOp : "project_delete", projectName : dijit.byId( "projectsGrid").selection.getSelected( )[0].projectName},
				load		: function( data, ioArgs) {
					if ( data == "ERROR") {
				        dijit.byId('toaster').setContent('Backend error. Could not delete project, please try later.', 'fatal');
				        dijit.byId('toaster').show();							
						return;
					}
					dijit.byId( "projectsGrid").removeSelectedRows();
			        dijit.byId('toaster').setContent('Project deleted successefuly.', 'fatal');
			        dijit.byId('toaster').show();
					if ( dijit.byId( "personalGrid")) {
						dijit.byId( "personalGrid").store.close( );
						dijit.byId( "personalGrid").store.fetch( );
					}
					if ( dijit.byId( "projectOrdersGrid")) {
						dijit.byId( "projectOrdersGrid").store.close( );
						dijit.byId( "projectOrdersGrid").store.fetch( );
					}
					if ( dijit.byId( "instrumentOrdersGrid")) {
						dijit.byId( "instrumentOrdersGrid").store.close( );
						dijit.byId( "instrumentOrdersGrid").store.fetch( );
					}
				},
				error		: function( ) {
			        dijit.byId('toaster').setContent('Backend error. Could not delete project, please try later.', 'fatal');
			        dijit.byId('toaster').show();							
				}
			});
		}
}